<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <p> 数组的求和和平均值</p>
        <p>求最大值</p>
        <p>存数组</p>
        <p>数组去重</p>

    </div>
    <script>
        var arr = [1, 3, 4, 6, 6, 6, 6, 7, 8, 9, 11, 11, 1, 3, 7, 2, 22, 2];

        // 数组的求和和平均值
        var sum = 0;
        var average = 0;//平均数
        for (let index = 0; index < arr.length; index++) {
            sum += arr[index] //计算每一个元素相加
        }
        average = sum / arr.length
        console.log(sum, average);


        // 求最大值
        var max = arr[0];
        for (let index = 1; index < arr.length; index++) {
            if (arr[index] > max) {
                max = arr[index]
            }
        }
        console.log(max, "最大值");


        //存数组1
        var arrNew = [];
        var j = 0;
        for (let index = 0; index < arr.length; index++) {
            if (arr[index] > 7) {
                arrNew[j] = arr[index];
                j++;
            }
        }
        console.log(arrNew, "存数组");

        //存数组2
        var arrNew = [];
        //  根据数组元素的长度
        for (let index = 0; index < arr.length; index++) {
            if (arr[index] > 7) {
                arrNew[arrNew.length] = arr[index];
            }
        }
        console.log(arrNew, "存数组2");

        // 数组删除指定元素
        var newArr = []
        for (let index = 0; index < arr.length; index++) {
            if (arr[index] != 6) {
                newArr[newArr.length] = arr[index]
            }
        }
        console.log("数组删除指定元素", newArr);



    </script>
</body>

</html>